<script setup>
const props = defineProps({
	isVisible: {
		type: Boolean,
		default: false,
		required: true,
	},
	type: {
		type: String,
		default: 'success'
	},
	title: {
		type: String,
		default: ''
	},
	content: {
		type: String,
		default: ''
	},
	confirm: {
		type: String,
		default: '确 认'
	},
	close: {
		type: String,
		default: ''
	}
})

const emits = defineEmits(['close', 'confirm'])

const closeModal = () => {
	props.isVisible = false
	emits('close')
}

const confirmModal = () => {
	props.isVisible = false
	emits('confirm', false)
}
</script>

<template>
	<div class="modal-mask" v-show="props.isVisible">
		<div class="modal-wrapper" :class="{'modal-error': props.type == 'error', 'modal-success': props.type == 'success', 'modal-warning': props.type == 'warning'}">
<!--			<div class="modal-close" @click="closeModal" v-if="props.close != ''">-->
<!--				<img src="https://ouan-retail.oss-cn-shenzhen.aliyuncs.com/web/tips/%E5%85%B3%E9%97%AD.png" alt="">-->
<!--			</div>-->
			<div class="modal-container">
				<div class="modal-header">
					<slot name="header">
						<div class="header-error">
							<img v-if="props.type == 'error'" src="https://ouan-retail.oss-cn-shenzhen.aliyuncs.com/web/tips/%E5%88%A0%E9%99%A4.png" alt="">
							<img v-if="props.type == 'success'" src="https://ouan-retail.oss-cn-shenzhen.aliyuncs.com/web/tips/%E5%AE%A1%E6%A0%B8%E9%80%9A%E8%BF%87%20(1).png" alt="">
							<img v-if="props.type == 'warning'" src="https://ouan-retail.oss-cn-shenzhen.aliyuncs.com/web/icon/%E6%8F%90%E7%A4%BA.png" alt="">
							<img v-if="props.type == 'waiting'" src="https://ouan-retail.oss-cn-shenzhen.aliyuncs.com/web/icon/%E5%AE%A1%E6%A0%B8%E4%B8%AD.png" alt="">
						</div>
					</slot>
				</div>
				<div class="modal-body">
					<slot>
						<p v-if="props.title != ''">{{ props.title }}</p>
						<text v-if="props.content != ''">{{ props.content }}</text>
					</slot>
				</div>
				<div class="modal-footer">
					<button v-if="props.close != ''" class="close" @click="closeModal">{{ props.close }}</button>
					<button v-if="props.confirm != ''" class="confirm" @click="confirmModal">{{ props.confirm }}</button>
				</div>
			</div>
		</div>
	</div>
</template>

<style scoped lang="scss">
.modal-mask {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: center;
	z-index: 999;
}

.modal-wrapper {
	max-width: 352px;
	min-width: 302px;
	border-radius: 5px 5px 5px 5px;
	position: relative;
	background: #FFFFFF;
}
.modal-error {
	background: linear-gradient( 180deg, #FFE3E1 0%, #FFFFFF 28%);
}
.modal-success {
	background: linear-gradient( 180deg, #F0FFE3 0%, #FFFFFF 34%);
}
.modal-warning {
	background: linear-gradient( 180deg, #FFE3E1 0%, #FFFFFF 28%);
}

.modal-close {
	width: 12px;
	height: 12px;
	position: absolute;
	top: 10px;
	right: 10px;
	cursor: pointer;
}
.modal-close img {
	width: 100%;
	height: 100%;
}

.modal-container {
	/* 样式按需定制 */

}

.modal-header, .modal-body, .modal-footer {
	display: flex;
	justify-content: center;
	align-items: center;
	border-radius: 0 0 5px 5px;
}


.modal-header {
	padding: 20px 32px;
}
.modal-header img {
	width: 38px;
	height: 38px;
}

.header-error {
	display: flex;
	justify-content: space-around;
	align-items: center;
}
.header-error img {
	width: 44px;
	height: 47px;
}

.modal-body {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	padding: 0 32px;
	font-size: 13px;
	color: #333333;
}
.modal-body p {
	font-size: 16px;
	color: #000000;
}
.modal-body text {
	margin-top: 10px;
	font-size: 14px;
	color: #444444;
}

.modal-footer {
	height: 57px;
	background: #F8F5F3;
	margin-top: 22px;
}
.modal-footer .close {
	font-size: 13px;
	color: #FC661C;
	background: rgba(252,102,28,0.12);
	border-radius: 3px 3px 3px 3px;
	padding: 6px 22px;
	border: none !important;
	cursor: pointer;
	margin-right: 10px;
}
.modal-footer .close:hover {
	color: #FFFFFF;
	background: #ffb07d;
}
.modal-footer .confirm {
	font-size: 13px;
	color: #FFFFFF;
	background: #FC661C;
	border-radius: 3px 3px 3px 3px;
	padding: 6px 22px;
	border: none !important;
	cursor: pointer;
	margin-left: 10px;
}
.modal-footer .confirm:hover {
	color: #FFFFFF;
	background: #ffb07d;
}
</style>